package com.moleq.logic;

import android.app.ProgressDialog;
import android.content.Context;

import com.moleq.dialog.CheckOutDialog;
import com.moleq.dialog.DateSelectionDialog;
import com.moleq.dialog.FuncSelectionDialog2;
import com.moleq.dialog.InputAgeInfoDialog;
import com.moleq.dialog.InputCvvInfoDialog;
import com.moleq.dialog.InputWicInfoDialog;
import com.moleq.dialog.ItemCouponDialog;
import com.moleq.dialog.ItemDiscountDialog2;
import com.moleq.dialog.LoginDialog;
import com.moleq.dialog.MessageBox;
import com.moleq.dialog.MessageDialog;
import com.moleq.dialog.OpenDeptDialog;
import com.moleq.dialog.PaymentDialog2;
import com.moleq.dialog.PriceChangeDialog;
import com.moleq.dialog.ShiftInfoDialog;
import com.moleq.dialog.TareInfoDialog;
import com.moleq.dialog.TransDiscountDialog;
import com.moleq.enums.ItemType;
import com.moleq.itemsetting.tools.MGCreateFiles;
import com.moleq.models.GlobalInfo;
import com.moleq.models.ItemSales;
import com.moleq.models.SaleListItem;
import com.moleq.mgpos.activities.R;
import com.moleq.mgpos.activities.SaleActivity;
import com.moleq.util.MoleQUtil;

public class DialogManager {

	public static final int OPEN_DEPTMENT = 0;
	public static final int FUNCTION_SELECTION = 1;
	public static final int CHECK_OUT = 2;
	public static final int PAYMENT_SELECT = 3;
	public static final int PROGRESS = 4;
	public static final int PROCESSING_PAYMENT = 5;
	public static final int TRANS_DISCOUNT = 6;
	public static final int ITEM_COUPON = 7;
	public static final int TARE_INFO = 8;
	public static final int ITEM_DISCOUNT = 9;
	public static final int PROCESSING_POS_LINE = 10;
	public static final int DATE_SELECTION_DIALOG = 11;
	public static final int DISCOUNT_LINK_DIALOG = 12;
	public static final int PRICE_CHANGE = 13;
	public static final int SHIFT = 14;
	public static final int USER_APPROVAL = 15;
	public static final int WIC = 16;
	public static final int CVV = 17;
	public static final int PROCESSING_PRINT_RECEIPT = 18;
	
	private static OpenDeptDialog mOpenDepDialog;
	// private static List<DialogInterface> dialogs = new
	// ArrayList<DialogInterface>();
	private static FuncSelectionDialog2 mFunctionSelectionDialog;
	private static CheckOutDialog mCheckOutDialog;
	private static PaymentDialog2 mPaymentDialog2;
	private static ProgressDialog mProgressDlg;
	private static ProgressDialog mProcessingPaymentDlg;
	private static TransDiscountDialog mDiscountDialog;
	private static ItemCouponDialog mItemCouponDialog;
	private static TareInfoDialog mTareInfoDialog;
	private static ItemDiscountDialog2 mItemDiscountDialog;
	private static ProgressDialog mProcessingPosLine;
	private static DateSelectionDialog mDateSelectionDialog;
	private static PriceChangeDialog mPriceChangeDialog;
	private static LoginDialog mLoginDialog;
	private static InputAgeInfoDialog mInputAgeInfoDialog;
	private static ShiftInfoDialog mShiftInfoDialog;
	private static InputWicInfoDialog mInputWicInfoDialog;
	private static InputCvvInfoDialog mInputCvvInfoDialog;
	private static ProgressDialog mProcessingPrintReceipt;
	
	private static MGCreateFiles mMGCreateFiles = new MGCreateFiles();
	
	public static void buildDialogs(Context appContext) {
		
		mOpenDepDialog = new OpenDeptDialog(appContext);
		mFunctionSelectionDialog = new FuncSelectionDialog2(appContext);
		
		mCheckOutDialog = new CheckOutDialog(appContext);
		mPaymentDialog2 = new PaymentDialog2(appContext, R.style.dialog);

		mProgressDlg = new ProgressDialog(appContext);
		mProgressDlg.setTitle("");
		mProgressDlg.setMessage(appContext.getText(R.string.dialog_message_proess_wait));
		mProgressDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);

		mProcessingPaymentDlg = new ProgressDialog(appContext);
		mProcessingPaymentDlg.setTitle("");
		mProcessingPaymentDlg.setMessage(appContext.getText(R.string.msg_proess_payment));
		mProcessingPaymentDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);

		mProcessingPosLine = new ProgressDialog(appContext);
		mProcessingPosLine.setTitle("");
		mProcessingPosLine.setMessage(appContext.getText(R.string.msg_load_item_proess_wait));
		mProcessingPosLine.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		
		mProcessingPrintReceipt = new ProgressDialog(appContext);
		mProcessingPrintReceipt.setTitle("");
		mProcessingPrintReceipt.setMessage(appContext.getText(R.string.msg_printing_proess_wait));
		mProcessingPrintReceipt.setProgressStyle(ProgressDialog.STYLE_SPINNER);

		mDiscountDialog = new TransDiscountDialog(appContext);
		
		mItemCouponDialog = new ItemCouponDialog(appContext);
		
		mTareInfoDialog = new TareInfoDialog(appContext);
		
		mItemDiscountDialog = new ItemDiscountDialog2(appContext);
		
		mDateSelectionDialog = new DateSelectionDialog(appContext);
		
		mPriceChangeDialog = new PriceChangeDialog(appContext);
		
		mLoginDialog = new LoginDialog(appContext);
		
		mInputAgeInfoDialog = new InputAgeInfoDialog(appContext,appContext);
		
		mShiftInfoDialog = new ShiftInfoDialog(appContext, appContext);
		
		mInputWicInfoDialog = new InputWicInfoDialog(appContext, appContext);
		
		mInputCvvInfoDialog = new InputCvvInfoDialog(appContext, appContext);
		
	}

	public static void show(Context appContext, int dialogID) {
		show(appContext, dialogID, "");
	}

	public static void show(Context appContext, int dialogID, String value) {

		switch (dialogID) {
		case OPEN_DEPTMENT:
			if (mOpenDepDialog == null || mOpenDepDialog.isShowing())
				return;
			mOpenDepDialog.show();
			break;

		case FUNCTION_SELECTION:
			if (mFunctionSelectionDialog == null || mFunctionSelectionDialog.isShowing())
				return;
			mFunctionSelectionDialog.show();
			break;

		case CHECK_OUT:
			if (mCheckOutDialog == null || mCheckOutDialog.isShowing())
				return;
			mCheckOutDialog.show();
			break;

		case PAYMENT_SELECT:
			if (mPaymentDialog2 == null || mPaymentDialog2.isShowing())
				return;
			mPaymentDialog2.show();
			break;

		case PROGRESS:
			if (mProgressDlg == null || mProgressDlg.isShowing())
				return;
			mProgressDlg.show();
			break;

		case PROCESSING_PAYMENT:
			if (mProcessingPaymentDlg == null || mProcessingPaymentDlg.isShowing())
				return;
			mProcessingPaymentDlg.show();
			break;
		case PROCESSING_POS_LINE:

			if (mProcessingPosLine == null || mProcessingPosLine.isShowing())
				return;
			mProcessingPosLine.show();
			break;

		case TRANS_DISCOUNT:
			if (mDiscountDialog == null || mDiscountDialog.isShowing())
				return;
			mDiscountDialog.show();
			break;

		case ITEM_COUPON:
			if (mItemCouponDialog == null || mItemCouponDialog.isShowing())
				return;
			mItemCouponDialog.show();
			break;

		case TARE_INFO:
			if (mTareInfoDialog == null || mTareInfoDialog.isShowing())
				return; 
			mTareInfoDialog.show();
			break;

		case ITEM_DISCOUNT:

			if (mItemDiscountDialog == null || mItemDiscountDialog.isShowing())
				return;
			mItemDiscountDialog.show();
			break;

		case DATE_SELECTION_DIALOG:
			
			if(GlobalInfo.getInstance().calendar_type){
				if (mDateSelectionDialog == null || mDateSelectionDialog.isShowing())
					return;

				mDateSelectionDialog.show();
			}else{
				if (mInputAgeInfoDialog == null || mInputAgeInfoDialog.isShowing())
					return;
				
				mInputAgeInfoDialog.show();
			}
			
			break;
		case PRICE_CHANGE:
			if (mPriceChangeDialog == null || mPriceChangeDialog.isShowing())
				return;
			mPriceChangeDialog.show();
			break;
		
		case SHIFT:
			if (mShiftInfoDialog == null || mShiftInfoDialog.isShowing())
				return;
			mShiftInfoDialog.show();
			break;
			
		case USER_APPROVAL:
			if(mLoginDialog == null || mLoginDialog.isShowing())
				return;
			mLoginDialog.show();
			break;
		case WIC:
			if(mInputWicInfoDialog == null || mInputWicInfoDialog.isShowing())
				return;
			mInputWicInfoDialog.show();
			break;
		case CVV:
			if(mInputCvvInfoDialog == null || mInputCvvInfoDialog.isShowing())
				return;
			mInputCvvInfoDialog.show();
			break;
		case PROCESSING_PRINT_RECEIPT:
			if (mProcessingPrintReceipt == null || mProcessingPrintReceipt.isShowing())
				return;
			mProcessingPrintReceipt.show();
			break;
		}
	}

	public static void hide(int dialogID) {
		switch (dialogID) {
		case OPEN_DEPTMENT:
			if (mOpenDepDialog != null && mOpenDepDialog.isShowing())
				mOpenDepDialog.dismiss();
			break;
		case FUNCTION_SELECTION:
			if (mFunctionSelectionDialog != null && mFunctionSelectionDialog.isShowing())
				mFunctionSelectionDialog.dismiss();
			break;

		case CHECK_OUT:
			if (mCheckOutDialog != null && mCheckOutDialog.isShowing())
				mCheckOutDialog.dismiss();
			break;
		case PAYMENT_SELECT:
			if (mPaymentDialog2 != null && mPaymentDialog2.isShowing())
				mPaymentDialog2.dismiss();
			break;

		case PROGRESS:
			if (mProgressDlg != null && mProgressDlg.isShowing())
				mProgressDlg.dismiss();

			break;

		case PROCESSING_PAYMENT:
			if (mProcessingPaymentDlg != null && mProcessingPaymentDlg.isShowing())
				mProcessingPaymentDlg.dismiss();

			break;

		case PROCESSING_POS_LINE:

			if (mProcessingPosLine != null && mProcessingPosLine.isShowing())
				mProcessingPosLine.dismiss();

			break;

		case TRANS_DISCOUNT:
			if (mDiscountDialog != null && mDiscountDialog.isShowing())
				mDiscountDialog.dismiss();

			break;
		case ITEM_COUPON:
			if (mItemCouponDialog != null && mItemCouponDialog.isShowing())
				mItemCouponDialog.dismiss();

			break;
		case TARE_INFO:
			if (mTareInfoDialog != null && mTareInfoDialog.isShowing())
				mTareInfoDialog.dismiss();
			break;

		case ITEM_DISCOUNT:
			if (mItemDiscountDialog != null && mItemDiscountDialog.isShowing())
				mItemDiscountDialog.dismiss();
			break;
		case DATE_SELECTION_DIALOG:
			if (mDateSelectionDialog != null && mDateSelectionDialog.isShowing())
				mDateSelectionDialog.dismiss();
			if (mInputAgeInfoDialog != null && mInputAgeInfoDialog.isShowing())
				mInputAgeInfoDialog.dismiss();
			
			break;
		case PRICE_CHANGE:
			if (mPriceChangeDialog != null && mPriceChangeDialog.isShowing())
				mPriceChangeDialog.dismiss();
			
			break;
		
		case SHIFT:
			if (mShiftInfoDialog != null && mShiftInfoDialog.isShowing())
				mShiftInfoDialog.dismiss();
			
			break;
			
		case USER_APPROVAL:
			if(mLoginDialog != null && mLoginDialog.isShowing())
				mLoginDialog.dismiss();
			
			break;
		case WIC:
			if(mInputWicInfoDialog != null && mInputWicInfoDialog.isShowing())
				mInputWicInfoDialog.dismiss();
			
			break;
		case CVV:
			if(mInputCvvInfoDialog != null && mInputCvvInfoDialog.isShowing())
				mInputCvvInfoDialog.dismiss();
			
			break;
		case PROCESSING_PRINT_RECEIPT:

			if (mProcessingPrintReceipt != null && mProcessingPrintReceipt.isShowing())
				mProcessingPrintReceipt.dismiss();

			break;
		}

	}

	public static ProgressDialog createProgressDialog(Context context) {
		ProgressDialog dialog = new ProgressDialog(context);
		dialog.setMessage(context.getText(R.string.dialog_message_proess_wait));
		dialog.setIndeterminate(true);
		dialog.setCancelable(true);
		dialog.setCanceledOnTouchOutside(false);
		return dialog;
	}

}
